package com.kool.kauth.common.util;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author luyu
 */
@Slf4j
public class PropertyUtil {
    private static Properties properties = new Properties();

    static {
        load();
    }

    public static String getProp(String key) {
        String value = properties.getProperty(key);
        return value;
    }

    public static void load(){
        try {
            String path = System.getProperty("user.dir") + "/config/application.properties";
            InputStream in = new FileInputStream(new File(path));
            properties.load(in);
        } catch (Throwable e) {
            try {
                String path = System.getProperty("user.dir") + "/application.properties";
                InputStream in = new FileInputStream(new File(path));
                properties.load(in);
            } catch (Throwable e2) {
                try {
                    properties.load(PropertyUtil.class.getClassLoader().getResourceAsStream("config/application.properties"));
                } catch (Throwable e3) {
                    try {
                        properties.load(PropertyUtil.class.getClassLoader().getResourceAsStream("application.properties"));
                    } catch (Throwable e4) {
                        log.error("加载properties文件失败！");
                        log.error(e4.getMessage(), e4);
                    }
                }
            }
        }

    }
}
